﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InterfaceFiles
{
  public class BaseInterfaceHeader : IInterfaceHeader
  {
    internal IInterfaceReader reader;
    internal IInterfaceWriter writer;
    private List<string> titles;
    private List<string> nodes;

    internal BaseInterfaceHeader(IInterfaceReader reader)
      : this(reader, null)
    {
    }

    internal BaseInterfaceHeader(IInterfaceReader reader, IInterfaceWriter writer)
    {
      this.reader = reader;
      this.writer = writer;
      titles = new List<string>();
      nodes = new List<string>();
    }

    protected virtual string ReadTitle()
    {
      string title = reader.ReadString(80);
      return title;
    }

    protected virtual int ReadJulianDate()
    {
      int julianDate = reader.ReadInt();
      return julianDate;
    }

    protected virtual double ReadSecondsOfDay()
    {
      double secondsOfDay = reader.ReadDouble();
      return secondsOfDay;
    }

    protected virtual string ReadSourceBlock()
    {
      string sourceBlock = reader.ReadString(20);
      return sourceBlock;
    }

    protected virtual int ReadNumPollutants()
    {
      int numNodes = reader.ReadInt();
      return numNodes;
    }

    protected virtual int ReadNumNodes()
    {
      int numPollutants = reader.ReadInt();
      return numPollutants;
    }

    protected virtual double ReadAreaSqFt()
    {
      double areaSqFt = reader.ReadDouble();
      return areaSqFt;
    }

    protected virtual bool ReadAlphaNumIDs()
    {
      int alphaNumIDs = reader.ReadInt();
      return alphaNumIDs != 0;
    }

    protected virtual string ReadNode()
    {
      string node = reader.ReadString(16);
      return node;
    }

    protected virtual double ReadFlowMultiplier()
    {
      double flowMultiplier = reader.ReadDouble();
      return flowMultiplier;
    }

    #region IInterfaceHeader Implementation

    public string this[int index]
    {
      get
      {
        return titles[index];
      }
      set
      {
        titles[index] = value;
      }
    }

    public DateTime StartTime
    {
      get;
      set;
    }

    public string SourceBlock
    {
      get;
      set;
    }

    public int NumNodes
    {
      get;
      set;
    }

    public int NumPollutants
    {
      get;
      set;
    }

    public double Area_sqft
    {
      get;
      set;
    }

    public bool UseAlphaNumIDs
    {
      get;
      set;
    }

    public double FlowMultiplier
    {
      get;
      set;
    }
    public List<string> Titles
    {
      get
      {
        return titles ?? (titles = new List<string>());
      }
      set
      {
        titles = new List<string>(value);
      }
    }

    public List<string> Nodes
    {
      get
      {
        return nodes ?? (nodes = new List<string>());
      }
      set
      {
        nodes = new List<string>(value);
      }
    }

    public virtual void Read()
    {
      throw new NotImplementedException();
    }

    public virtual void Write()
    {
      throw new NotImplementedException();
    }

    public virtual void Write(IInterfaceHeader header)
    {
      throw new NotImplementedException();
    }
    #endregion
  }
}
